﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Statements;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Markup;
using Core = Vision.Core;

namespace Vision.Core.ActivityComponents.IO.File
{        
    /// <summary>
    /// 
    /// </summary>
	[ContentProperty("Body")]
	[System.ComponentModel.Designer(typeof(FileInfoDesigner))]
	public class FileInfo : NativeActivity
    {
        /// <summary>
        /// 
        /// </summary>        
        [Category("Input")]
        public InArgument<string> FilePath { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> Name { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> Extension { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> DirectoryName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> CreationTime { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> LastAccessTime { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> LastWriteTime { get; set; }

		/// <summary>
		/// 
		/// </summary>
		[Browsable(false)]
		[DefaultValue(null)]
		public ActivityAction<System.IO.FileInfo> Body { get; set; }

		public FileInfo()
        {
			this.Body = new ActivityAction<System.IO.FileInfo>()
            {
				Argument = new DelegateInArgument<System.IO.FileInfo>()
                {
                    Name = "fileInfo"
                }
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {
            System.IO.FileInfo fi = new System.IO.FileInfo(this.FilePath.Get(context));
            this.Name.Set(context, fi.Name);
            this.Extension.Set(context, fi.Extension);
            this.DirectoryName.Set(context, fi.DirectoryName);
            this.CreationTime.Set(context,fi.CreationTime);
            this.LastAccessTime.Set(context,fi.LastAccessTime);
            this.LastWriteTime.Set(context, fi.LastWriteTime);

			// schedule the next action
			if (this.Body != null && this.Body.Handler != null)
			{
				context.ScheduleAction(this.Body, fi);
			}

            fi = null;
        }
    }
}
